package com.digital.herbarium.task;

import com.digital.herbarium.Entity.SpecimenUrl;
import com.digital.herbarium.Util.Watermark;
import com.digital.herbarium.service.SpecimenService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Component
public class addWaterTask {

    @Autowired
    SpecimenService specimenService;
    @Value("${static.url}")
    private String staticurl;


    // @Scheduled(cron ="0 0 2,5,8 * * ?")
//    @Scheduled(cron = "0 */10 * * * *")
    // @Scheduled(cron = "0 0 23,0,2,4,5 * * ?")//晚上 11 点、12 点，凌晨 2 点、4 点、5 点执行任务
   // @Scheduled(cron = "0 0 13,15,17,19,22 * * ?")//晚上 11 点、12 点，凌晨 2 点、4 点、5 点执行任务
    public void batchAddWater() throws IOException {
        System.out.println(staticurl);
        PageInfo<SpecimenUrl> list =  specimenService.getNoWaterImage();
        if(list.getList().size() > 0){
//            添加水印
            List<String> plist = new ArrayList<>();
            for (int i = 0; i < list.getList().size(); i++) {
                String pnameUrl = list.getList().get(i).getImgUrl();
                String url = staticurl + File.separator + pnameUrl;
                System.out.println(url);
                plist.add(list.getList().get(i).getPicname());
                Watermark.addWaterMark(url,  "湖北省药检院数字标本馆");
            }

            specimenService.batchUpdateImage(plist);
        }

    }

}
